//管理用户数据
import { defineStore } from "pinia";
import { ref } from "vue";

export const useUserStore = defineStore(
  "user",
  () => {
    //定义用户数据store
    const userInfo = ref({});
    const userToken = ref();
    //定义接口数据的action
    const setUserInfo = (data) => {
      userInfo.value = data;
    };
    //保存token
    const setUserToken = (data) => {
      userToken.value = data;
    };

    //退出时清除用户信息
    const clearUserInfo = () => {
      userInfo.value = "";
      userToken.value = "";
    };

    //以对象形式把store和action返回
    return {
      userInfo,
      userToken,
      setUserInfo,
      setUserToken,
      clearUserInfo,
    };
  },
  {
    persist: true,
  }
);
